//
//  ListFoodViewController.m
//  ZooNgonDoiOS
//
//  Created by Trung sound on 8/1/12.
//  Copyright (c) 2012 Personal. All rights reserved.
//

#import "ListFoodViewController.h"
#import "FoodDetailViewController.h"

@implementation ListFoodViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithObject:(NSString *)a {
    [self initWithNibName:nil bundle:nil];
    if (self) {
        [self initHeaderView];
        [self initContent];
    }
    return self;
}

- (void) initHeaderView {
    _vHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 48)];
    _vHeader.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:IMG_NAV_BACKGROUND]];
    
    _btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 48, 48)];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_NORMAL] forState:UIControlStateNormal];
    [_btnBack setBackgroundImage:[UIImage imageNamed:IMG_BACK_SELECTED] forState:UIControlStateHighlighted];
    [_btnBack addTarget:self action:@selector(backClicked) forControlEvents:UIControlEventTouchUpInside];
    
    [_vHeader addSubview:_btnBack];
    
    [self.view addSubview:_vHeader];
    
    [_btnBack release];
    [_vHeader release];
}

- (void)initContent {
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:IMG_VIEW_BACKGROUND]]];
    _listFoodTableView = [[ListFoodTableView alloc]initWithFrame:CGRectMake(0, 48, self.view.bounds.size.width, self.view.bounds.size.height-48)];
    _listFoodTableView.backgroundColor = [UIColor clearColor];
    _listFoodTableView.parentView = self;
    
    [self.view addSubview:_listFoodTableView];
    [_listFoodTableView release];
}

- (void) pushToFoodDetailView:(FoodDetailViewController *)foodDetailViewController {
//    [self.navigationController pushViewController:foodDetailViewController animated:YES];
    [self presentModalViewController:foodDetailViewController animated:YES];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)backClicked {
    [self dismissModalViewControllerAnimated:YES];
}
#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
